#include "ControlLayer.h"
#include "SimpleAudioEngine.h"

using namespace cocos2d;
using namespace CocosDenshion;

ControlLayer* ControlLayer::node() {
	ControlLayer *layer = ControlLayer::create();
	return layer;
}

bool ControlLayer::init() {
	if(!CCLayer::init())
	{
		return false;
	}
	this->setTouchEnabled(true);
	this->initJoystickAndButtons();
	return true;
}
void ControlLayer::initJoystickAndButtons() {
	CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
	CCRect joystickBaseDimensions = CCRectMake(0, 0, 128.0f, 128.0f);
	CCRect jumpButtonDimensions = CCRectMake(0, 0, 64.0f, 64.0f);

	CCPoint joystickBasePosition;
	CCPoint jumpButtonPosition;

	joystickBasePosition = ccp(screenSize.width*0.07f, screenSize.height*0.11f);
	jumpButtonPosition = ccp(screenSize.width*0.93f, screenSize.height*0.11f);

	//Joystick
	SneakyJoystickSkinnedBase *joystickBase = SneakyJoystickSkinnedBase::node();
	joystickBase->setPosition(joystickBasePosition);
	joystickBase->setBackgroundSprite(CCSprite::create("dpadDown.png"));
	joystickBase->setThumbSprite(CCSprite::create("joystickDown.png"));
	SneakyJoystick *aJoystick = new SneakyJoystick();
	aJoystick->initWithRect(joystickBaseDimensions);
	aJoystick->autorelease();

	joystickBase->setJoystick(aJoystick);
	leftJoystick = joystickBase->getJoystick();
	this->addChild(joystickBase);

	//Jump button
	SneakyButtonSkinnedBase *jumpButtonBase = SneakyButtonSkinnedBase::node();
	jumpButtonBase->setPosition(jumpButtonPosition);
	jumpButtonBase->setDefaultSprite(CCSprite::create("jumpUp.png"));
	jumpButtonBase->setActivatedSprite(CCSprite::create("jumpDown.png"));
	jumpButtonBase->setPressSprite(CCSprite::create("jumpDown.png"));
	SneakyButton *aButton = new SneakyButton();
	aButton->initWithRect(jumpButtonDimensions);
	aButton->autorelease();

	jumpButtonBase->setButton(aButton);
	jumpButton = jumpButtonBase->getButton();
	jumpButton->setIsToggleable(false);
	this->addChild(jumpButtonBase);
}
